<style> .radio-input div{
        float: left;
        margin-left: .5em;
    }</style>
<?php if((arg(2) == 'edit'|| arg(2) == "add") && !empty($_GET['farmer_id'])) {
    echo get_template_header_info($form['#farmer']);
}?>
<?php
if(isset($_GET['addr_id'])&& !empty($_GET['addr_id'])) {
    echo get_template_header_info($_GET['addr_id'], 'village');
}
?>
<div class="hp-tab-newprd">
    <?php if(!empty($_GET['farmer_id'])){?>
        <img style="margin-left: 85px;" src="<?php echo base_path()?>sites/all/themes/tweme/images/images/farmer.png"/>
    <?php }else if(!empty($_GET['addr_id'])){ ?>
        <img style="margin-left: 75px;" src="<?php echo base_path()?>sites/all/themes/tweme/images/images/village.png"/>
    <?php }?>
    <ul class="j-sw-nav">
        <?php if (arg(2) == "add" && empty($_GET['farmer_id']) && empty($_GET['addr_id'])) { ?>
            <li class="newprd-s1 tab-li"><a href="<?php echo base_path();?>farmer/plant_info/list">查看</a></li>
        <?php if(user_access('add plant_info')){ ?>
            <li class="newprd-s2 tab-li on"><a href="<?php echo base_path();?>farmer/plant_info/add">添加</a></li>
        <?php }
        } else if((arg(2) == "add" && !empty($_GET['farmer_id'])) || (arg(2) == "edit" && !empty($_GET['farmer_id']))){?>
            <?php echo get_tab($form['#farmer'],'plant_info'); ?>
        <?php }
        else if(arg(2) == "edit" && empty($_GET['farmer_id']) && empty($_GET['addr_id'])){?>
            <li class="newprd-s1 tab-li"><a href="<?php echo base_path();?>farmer/plant_info/list">查看</a></li>
            <?php if(user_access('add plant_info')){ ?>
            <li class="newprd-s2 tab-li"><a href="<?php echo base_path();?>farmer/plant_info/add">添加</a></li>
            <?php }?>
            <li class="newprd-s3 tab-li on"><a>修改</a></li>
        <?php } else if((arg(2) == "add" && !empty($_GET['addr_id']))||(arg(2) == "edit" && !empty($_GET['addr_id']))){?>
            <?php echo get_tab($_GET['addr_id'],'plant_info','village'); ?>
        <?php }?>
    </ul>
    <div class="table-div">
        <img src="<?php echo base_path()?>sites/all/themes/tweme/images/images/jb_info.gif" style="margin: 15px 0px;">
        <div class="small-select small-input column" style="clear:both">
            <?php global $user;
            $user_info = _get_user_info($user->uid);
            if(get_user_role_name($user->uid) === '农户') {?>
                <?php print render($form['farmer']); ?>
            <?php }else if(empty($_GET['farmer_id'])){?>
                <div class="small-input address-search">
                    <div class="form-label"><span class="required">*</span>农户:</div>
                    <?php print render($form['farmer_name']);
                    if(empty($form['#plant_info_id'])){
                        print render($form['select_farmer_button']);
                    }
                    ?>
                </div>
            <?php }?>
        </div>
        <div class="middle-select small-input column" style="clear:both">
            <div class="small-input address-search"><div class="form-label"><span class="required">*</span>作物:</div><?php print render( $form['basic_info']['plant']); ?></div>
        </div>
        <div class="small-select small-input column" style="clear:both">
            <div class="small-div"><div class="form-label">种植品种:</div><?php print render($form['basic_info']['seed']); ?></div>
            <div class="small-div"><div class="form-label">种植面积(亩):</div><?php print render($form['basic_info']['plant_area']); ?></div>
        </div>
        <div class="" style="clear:both;"><div class="form-label">一年生/多年生:</div><div class="radio-input"><?php print render($form['basic_info']['perennial']); ?></div></div>
        <div class="small-select small-input column" style="clear:both">
            <div class="form-label perennial_change_title">
                <?php if($form['#perennial'] == 1){?>
                播种<?php }else{?>实施<?php }?>日期:</div><?php print render( $form['basic_info']['sow_date']); ?>
        </div>
        <div class="small-select small-input column" style="clear:both">
            <div class="small-div"><div class="form-label">株距(厘米):</div><?php print render($form['basic_info']['plant_space']); ?></div>
            <div class="small-div"><div class="form-label">行距(厘米):</div><?php print render($form['basic_info']['row_space']); ?></div>
        </div>
        <div class="small-select small-input column" style="clear:both">
            <div class="small-div"><div class="form-label">灌溉方式:</div><?php print render($form['basic_info']['irrigation']); ?></div>
        </div>
        <div class="small-select small-input column" style="clear:both">
            <div class="form-label">收获日期:</div><?php print render( $form['basic_info']['harvest_date']); ?>
        </div>
        <div class="small-select small-input column" style="clear:both">
            <div class="small-div"><div class="form-label">一般产量（千克/亩）:</div><?php print render($form['economy_info']['general_yield']); ?></div>
            <div class="small-div"><div class="form-label">密度:</div><?php print render($form['economy_info']['density']); ?></div>
        </div>
        <img src="<?php echo base_path()?>sites/all/themes/tweme/images/images/demonstration.gif" style="margin: 15px 0px;">
        <div class="small-select small-input column" style="clear:both">
            <div class="small-div"><div class="form-label">示范面积（亩）:</div><?php print render($form['economy_info']['demonstration_area']); ?></div>
            <div class="small-div"><div class="form-label">撒可富赠肥量（公斤）:</div><?php print render($form['economy_info']['sacf_fertilizer']); ?></div>
        </div>
        <div class="small-select small-input column" style="clear:both">
            <div class="small-div"><div class="form-label">撒可富品种:</div><?php print render($form['economy_info']['sacf']); ?></div>
        </div>
        <img src="<?php echo base_path()?>sites/all/themes/tweme/images/images/mu_input.gif" style="margin: 15px 0px;">
        <div class="small-select small-input column" style="clear:both">
            <div class="small-div"><div class="form-label">种子开销（元/亩）:</div><?php print render($form['economy_info']['seed_cost']); ?></div>
            <div class="small-div"><div class="form-label">肥料开销（元/亩）:</div><?php print render($form['economy_info']['fertilizer_cost']); ?></div>
        </div>
        <div class="small-select small-input column" style="clear:both">
            <div class="small-div"><div class="form-label">农药开销（元/亩）:</div><?php print render($form['economy_info']['pesticide_cost']); ?></div>
            <div class="small-div"><div class="form-label">农机开销（元/亩）:</div><?php print render($form['economy_info']['machinery_cost']); ?></div>
        </div>
        <div class="small-select small-input column" style="clear:both">
            <div class="small-div"><div class="form-label">其他开销（元/亩）:</div><?php print render($form['economy_info']['others_cost']); ?></div>
            <div class="small-div"><div class="form-label">产品单价（元/公斤）:</div><?php print render($form['economy_info']['unit_price']); ?></div>
        </div>
        <div class="small-select small-input column" style="clear:both">
            <div class="small-div"><div class="form-label">总投入（元）:</div><?php print render($form['economy_info']['total_input']); ?></div>
            <div class="small-div"><div class="form-label">收入（元）:</div><?php print render($form['economy_info']['income']); ?></div>
        </div>
        <div class="small-select small-input column" style="clear:both">
            <div class="small-div"><div class="form-label">净收入（元）:</div><?php print render($form['economy_info']['net_income']); ?></div>
            <div class="small-div"><div class="form-label">其他收益（元/亩）:</div><?php print render($form['economy_info']['other_yield']); ?></div>
        </div>
        <div class="small-select max-big-input column" style="clear:both">
            <div class="form-label">专项活动:</div><?php print render($form['special_activities']); ?>
        </div>
        <div class="small-select small-input column" style="clear:both">
            <div class="form-label">备注:</div><div style="margin-left: 11.3em; "><?php print render( $form['comments']); ?></div>
        </div>

        <?php
                $plant_info_id = 0;
                foreach($form['#fertilization']['#markup'] as $key=>$value){
                    $html ='<div class="fertilization-div '.$value->id.'"><div class="fertilization-title">'.$value->type;
                    $html .= '<span class="fertilization-delete" onclick="delete_fertilizer(\'fertilization_info\',\''.$value->id.'\')">-</span></div>';
                    $html .= '<ul><li>肥料名称:'.$value->variety_name.$value->proportion.$value->SM."</li>";
                    $html .= '<li>用量:'.$value->fertilizer_quantity."</li>";
                    $html .= '<li>施肥日期:'.$value->fertilization_date."</li>";
                    $html .= '<li>施肥方法:'.$value->fertilization_method."</li></ul></div>";
                    $plant_info_id = $value->plant_info_id;
                    print render($html);
                }
        ?>
        <div class="fertilization-div add-fertilization-div" id='add-fertilizer-info' data-toggle="modal" data-target="#fertilizerPlantInfoModal">
            <div class="fertilization-title"><span style="font-weight: bold">继续添加施肥习惯</span></div>
            <span class="add-fertilization">+</span></div>
        <div class="add-submit" style="text-align: center"><?php print render($form['submit']); ?></div>
        <?php if(isset($form['#farmer'])&& !empty($form['#farmer'])){?>
            <ul class="table-ul-li">
                <li style=" padding: 2em 0;  float: right; margin-top: -5.8em;margin-right: 24em;"><a href="<?php echo base_path(); ?>farmer/plant_info/list?farmer_id=<?php echo $form['#farmer']?>">
                        <input class="btn btn-primary form-submit" type="button"  value="返回">
                    </a></li>
                <?php //if(user_access('add plant_info')){ ?>
                <!--            <li>|</li>-->
                <!--            <li><a href="--><?php //echo base_path(); ?><!--farmer/plant_info/add?farmer_id=--><?php //echo $form['#farmer']?><!--" --><?php //if(arg(2) == "add" && !empty($_GET['farmer_id'])){?><!--class="selected"--><?php //}?><!--添加</a></li>-->
                <!--            --><?php //}
                //            if(arg(2) == "edit" && !empty($_GET['farmer_id'])){?>
                <!--                <li>|</li>-->
                <!--                <li class="selected">详情</li>-->
                <!--            --><?php //}?>
            </ul>
        <?php }?>
        <?php if(isset($_GET['addr_id'])&& !empty($_GET['addr_id'])){?>
            <ul class="table-ul-li">
                <li  style=" padding: 2em 0;  float: right; margin-top: -5.8em;margin-right: 24em;"><a href="<?php echo base_path(); ?>farmer/plant_info/list?addr_id=<?php echo $_GET['addr_id']?>">
                        <input class="btn btn-primary form-submit" type="button"  value="返回">
                    </a></li>
                <!--                --><?php //if(user_access('add plant_info')){ ?>
                <!--                <li>|</li>-->
                <!--                <li><a href="--><?php //echo base_path(); ?><!--farmer/plant_info/add?addr_id=--><?php //echo $_GET['addr_id']?><!--" --><?php //if(arg(2) == "add" && !empty($_GET['addr_id'])){?><!--class="selected"--><?php //}?><!--添加</a></li>-->
                <!--                --><?php //}
                //                if(arg(2) == "edit" && !empty($_GET['addr_id'])){?>
                <!--                    <li>|</li>-->
                <!--                    <li class="selected">详情</li>-->
                <!--                --><?php //}?>
            </ul>
        <?php }?>
        <div style="clear: both"></div>
    </div>
</div>

<?php print drupal_render_children($form); ?>
</div></form>

<div>
    <div class="modal fade" id="farmerModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close"
                            data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        选择农户
                    </h4>
                </div>
                <div class="modal-body">
                    <?php echo @render(drupal_get_form('farmer_select_list_form',isset($_GET['addr_id'])&& !empty($_GET['addr_id'])?$_GET['addr_id']:'')); ?>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">关闭
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>

<div>
    <div class="modal fade" id="fertilizerPlantInfoModal" tabindex="-1" role="dialog" aria-labelledby="fertilizerPlantInfoModal" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close"
                            data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        施肥习惯
                    </h4>
                </div>
                <div class="modal-body">
                    <?php echo @render(drupal_get_form('fertilizer_extra_edit_form','fertilization_info','plant_info_id','',true));?>
                </div>
                <!--                <div class="modal-footer">-->
                <!--                    <button type="button" class="btn btn-default"-->
                <!--                            data-dismiss="modal">关闭-->
                <!--                    </button>-->
                <!---->
                <!--                </div>-->
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>
<form><div>
